package com.jxl.application.controller.controller;

import com.jxl.application.controller.convert.AuthRoleDtoConvert;
import com.jxl.dto.AuthRoleDto;
import com.jxl.dto.Result;
import com.jxl.domain.entity.AuthRoleBO;
import com.jxl.domain.service.AuthRoleDomainService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 用户模块
 */
@RestController
@RequestMapping("/role/")
public class RoleController {

    @Resource
    private AuthRoleDomainService authRoleDomainService;

    /**
     * 角色添加
     * @param authRoleDto
     * @return
     */
    @PostMapping("/add")
    public Result<Boolean> add(@RequestBody AuthRoleDto authRoleDto){
        try{
            AuthRoleBO authRoleBO =
                    AuthRoleDtoConvert.INSTANCE.convertDtoToRoleBO(authRoleDto);
            Boolean add = authRoleDomainService.add(authRoleBO);
            return Result.ok(add);
        }catch (Exception e){
            return Result.fail(e.getMessage());
        }
    }


    /**
     * 角色修改
     * @param authRoleDto
     * @return
     */
    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody AuthRoleDto authRoleDto){
        try{
            AuthRoleBO authRoleBO =
                    AuthRoleDtoConvert.INSTANCE.convertDtoToRoleBO(authRoleDto);
            Boolean add = authRoleDomainService.update(authRoleBO);
            return Result.ok(add);
        }catch (Exception e){
            return Result.fail(e.getMessage());
        }
    }

    /**
     * 角色删除
     * @param authRoleDto
     * @return
     */
    @PostMapping("/delete")
    public Result<Boolean> delete(@RequestBody AuthRoleDto authRoleDto){
        try{
            AuthRoleBO authRoleBO =
                    AuthRoleDtoConvert.INSTANCE.convertDtoToRoleBO(authRoleDto);
            Boolean add = authRoleDomainService.delete(authRoleBO);
            return Result.ok(add);
        }catch (Exception e){
            return Result.fail(e.getMessage());
        }
    }

}
